exports.punchIn = (req, res) => {

    //获取参数信息
    var bodyParams = req.routeInfo.bodyParams;

    var opr_create_time = bodyParams.opr_create_time;
    var opr_year = bodyParams.opr_year;
    var opr_month = bodyParams.opr_month;
    var opr_day = bodyParams.opr_day;
    var opr_uid = bodyParams.opr_uid;

    var GeneralConfiguration = 0;

    //查询考勤配置
    function searchGeneralConfiguration(cb) {

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.generalConfigurationSearch.Request_Api_Url,
                method: 'POST',
                data: {
                    fields: ["ogc_work_start_time"].join(",")
                }
            },
            function (data) {

                GeneralConfiguration = data.result.data[0].ogc_work_start_time;
                console.log(GeneralConfiguration);
                cb();

            }
        )

    }

    //计算迟到时间并保存数据
    function calculateLateTimeAndSavePunchData(cb) {
        var timeStr = common.dateFormat("hh:mm:ss", opr_create_time);
        var punchHours = parseInt(timeStr.split(":")[0]);
        var punchMinutes = parseInt(timeStr.split(":")[1]);
        var punchSeconds = parseInt(timeStr.split(":")[2]);
        var punchTimeSeconds = punchHours * 3600 + punchMinutes * 60 + punchSeconds;
        var configHours = parseInt(GeneralConfiguration.split(":")[0]);
        var configMinutes = parseInt(GeneralConfiguration.split(":")[1]);
        var configTimeSeconds = configHours * 3600 + configMinutes * 60;
        var lateTime = 0;
        var isLate = 0;
        var timeDifference = punchTimeSeconds - configTimeSeconds;
        if (timeDifference > 0) {
            lateTime = timeDifference;
            isLate = 1;
        }
        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.punchRecordAdd.Request_Api_Url,
                method: 'POST',
                data: {
                    opr_create_time: opr_create_time,
                    opr_year: opr_year,
                    opr_month: opr_month,
                    opr_day: opr_day,
                    opr_uid: opr_uid,
                    opr_is_late: isLate,
                    opr_late_time: lateTime,
                }
            },
            function (data) {
                console.log(data.result);
                cb();
            }
        )
    }

    F.Serial([searchGeneralConfiguration, calculateLateTimeAndSavePunchData], () => {
        RES.successResponse(res);
    })


}